import sys
from PySide6.QtWidgets import QWidget,QApplication,QHBoxLayout,QTableWidget,QTableWidgetItem,QLabel



class MyMainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()


    def setup_ui(self):
        self.resize(800, 600)
        #创建一个table_widgets
        table_widgtes = QTableWidget(5,6,self)
        table_widgtes.resize(800,600)

        h_box = QHBoxLayout()
        add_label = QLabel('修改')
        del_label = QLabel('删除')
        h_box.addWidget(add_label)
        h_box.addWidget(del_label)

        
        # 设置所有的表头
        table_widgtes.setHorizontalHeaderLabels(["a", 'b', 'c', 'd', 'e','f'])
        
        for i in range(5):
            # 设置行的表头
            # table_widgtes.horizontalHeaderItem(i)
            for j in range(6):
                if j != 5:
                    item = QTableWidgetItem(f"行{i},列{j}", type=j)
                else:
                    str_ = add_label.text() + '/' +del_label.text()
                    item = QTableWidgetItem(str_, type=j)
                table_widgtes.setItem(i, j, item)
        # 返回当前选中的item项
        # print(table_widgtes.currentColumn())
        # print(table_widgtes.itemFromIndex())
        # 单元格被点击触发的槽函数，返回的是行数
        table_widgtes.cellClicked.connect(self.cell_item)
    
    def cell_item(self,item):
        print("被惦记",item)
              
            


        





        

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyMainWindow()
    window.show()
    sys.exit(app.exec())
